package com.powernobug.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @Author: 肖云戈
 * @CreateTime: 2024-08-29
 * @Description: 暂时弃用
 */
@Aspect
@Component
public class ThreadLogAspect {

    @Pointcut("@annotation(com.powernobug.annotation.PrintThreadLog)")
    public void pointcutWhereMultiThreadSelect() {}

    @Around("pointcutWhereMultiThreadSelect()")
    public Object around(ProceedingJoinPoint joinPoint) {
        String currClassName = joinPoint.getSignature().getDeclaringType().getSimpleName();
        String currMethodName = joinPoint.getSignature().getName();

        Thread.currentThread().setName(currClassName + "." + currMethodName + "-" + Thread.currentThread().getId());

        System.out.println(Thread.currentThread().getName() + "：" + "开始查询...");
        Object proceed = null;
        try {
            proceed = joinPoint.proceed();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }

        System.out.println(Thread.currentThread().getName() + "：" + "查询完成！");
        return proceed;
    }
}
